
// register.js

function sendVerificationCode() {
    const button = document.getElementById('sendCodeBtn');
    button.disabled = true; // 禁用按钮，防止重复点击
    button.textContent = '已发送'; // 更改按钮文本

    // 发送验证码的逻辑
    const email = document.getElementById('email').value;
    fetch('/send_verification_code', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ email: email })
    })
    .then(response => response.json())
    .then(data => {
        alert(data.message); // 显示服务器响应的消息
    })
    .catch(error => console.error('Error:', error));

    // 10秒后允许用户再次发送验证码
    setTimeout(() => {
        button.disabled = false;
        button.textContent = '发送验证码';
    }, 10000); // 10000毫秒后执行
}

function validateForm() {
    // 表单验证逻辑
    // 确保表单填写完整并且数据格式正确
    const username = document.getElementById('username').value;
    const email = document.getElementById('email').value;
    const code = document.getElementById('verification_code').value;
    const password = document.getElementById('password').value;

    if (!username || !email || !code || !password) {
        alert('请填写所有字段。');
        return false;
    }
    return true;
}

document.addEventListener("DOMContentLoaded", function() {
    const inputs = document.querySelectorAll('.form-group input');
    inputs.forEach(input => {
        input.addEventListener('focus', function() {
            this.parentNode.classList.add('focused');
        });
        input.addEventListener('blur', function() {
            if (this.value === "") {
                this.parentNode.classList.remove('focused');
            }
        });
    });
});

document.getElementById('sendCodeBtn').addEventListener('click', function() {
   
});
